layui.config({
    base: "/js/modules/"
}).extend({
    "listView": "listView",
});
layui.use(['form', 'listView', 'laydate', 'jquery', 'common', 'table'], function () {
    let layDate = layui.laydate,
        form = layui.form,
        common = layui.common,
        layer = layui.layer,
        table = layui.table,
        $ = layui.$;

    layDate.render(
        {
            elem: "#beginTime", trigger: 'click'
        }
    );
    layDate.render(
        {
            elem: "#endTime", trigger: 'click'
        }
    );

    layui.listView.tableInit({
        id: 'deviceType',
        url: '/device/type/page',
        page: true,
        cols: [
            {field: 'number', title: '序号', fixed: 'true', type: 'numbers'},
            {field: 'parentName', title: '上级类型'},
            {field: 'name', title: '类型'},
            {
                field: 'isValid', title: '状态', templet: function (d) {
                    return d.isValid ? "有效" : "无效"
                }
            },
            {field: 'createTime', title: '创建时间'},
            {field: 'creator', title: '创建人'},
            {field: 'lastUpdTime', title: '最后修改时间'},
            {field: 'modifier', title: '修改人'},
            {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150}
        ]
    });

    $('#add').on('click', function () {
        layer.open({
            title: '新增设备类型',
            type: 2,
            area: ['600px', '400px'],
            fixed: false, //不固定
            maxmin: true,
            content: '/device/type/toAddDeviceType'
        });
    });

    //操作
    table.on('tool(deviceType)', function (obj) {
        var data = obj.data;
        if (obj.event === 'edit') {
            // layer.alert('编辑行：<br>'+ JSON.stringify(data))
            layer.open({
                title: '编辑设备类型',
                type: 2,
                area: ['800px', '350px'],
                fixed: false, //不固定
                maxmin: true,
                content: '/device/type/queryDeviceType?id=' + data.id
            });
        } else if (obj.event === 'param') {
            // layer.alert('编辑行：<br>'+ JSON.stringify(data))
            layer.open({
                title: '编辑设备类型接收参数',
                type: 2,
                area: ['60%', '60%'],
                fixed: false, //不固定
                maxmin: true,
                content: '/device/typeData?id=' + data.id
            });
        }
    });


});
